package com.pb.wkflow.api.service.impl;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.pb.infra.oth.entity.common.Result;
import com.pb.wkflow.api.controller.assembler.TaskHandOverAssembler;
import com.pb.wkflow.api.controller.request.TaskHandOverCreateRequest;
import com.pb.wkflow.api.controller.request.TaskHandOverQueryRequest;
import com.pb.wkflow.api.entity.TaskHandOverEntity;
import com.pb.wkflow.api.mapper.TaskHandOverMapper;
import com.pb.wkflow.api.service.TaskHandOverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 任务移交配置ServiceImpl
 * @author 苗益辉
 * @date 2022/12/26 15:02
 */
@Service
public class TaskHandOverServiceImpl implements TaskHandOverService {

    @Autowired
    TaskHandOverMapper taskHandOverMapper;

    @Override
    public Result searchByPage(Integer pageIndex, Integer pageSize, TaskHandOverQueryRequest request) {
        if (pageIndex != null && pageSize != null) {
            PageMethod.startPage(pageIndex, pageSize);
        }
        List<TaskHandOverEntity> list = taskHandOverMapper.selectList(request);
        return Result.ok(new PageInfo<TaskHandOverEntity>(list).getTotal(), list);
    }

    @Override
    public void insert(TaskHandOverCreateRequest request) {
        TaskHandOverEntity entity = TaskHandOverAssembler.assemblerToCreate(request);
        taskHandOverMapper.insert(entity);
    }

    @Override
    public void edit(TaskHandOverCreateRequest request) {
        TaskHandOverEntity entity = TaskHandOverAssembler.assemblerToEdit(request);
        taskHandOverMapper.edit(entity);
    }

    @Override
    public void delete(TaskHandOverCreateRequest request) {
        TaskHandOverEntity entity = TaskHandOverAssembler.assemblerToDelete(request);
        taskHandOverMapper.delete(entity);
    }
}
